package collection;

import java.util.*;

public class CollectionDemo6 {
    public static void main(String[] args) {
        Collection<String> c= new ArrayList();
        c.add("java");
        c.add("python");
        c.add("c++");
        c.add("web");
        //c.add(45); 规定了泛型 不能放入其他类型

        System.out.println(c.size());
        System.out.println(c.isEmpty());
        System.out.println(c.contains("java"));
        System.out.println(c.remove("c"));
        //c.clear();

        System.out.println(c);
        System.out.println("---新循环 方式--");
        for(String s : c){
            System.out.print(s+"  ");
        }
        System.out.println("");
        System.out.println("-----迭代器方式循环----");
       Iterator<String> it= c.iterator();
       while(it.hasNext()){
           System.out.print(it.next()+"  ");
       }

       Collection c2= new ArrayList();
       c2.add("java");
       c2.add("python");

       c.addAll(c2);
        System.out.println(c);
        System.out.println( c.containsAll(c2));


        System.out.println("----------list--------");
        List list = new ArrayList();
        list.addAll(c);
        System.out.println(list);
        System.out.println(c.size());
        System.out.println(c.isEmpty());
        System.out.println(c.contains("java"));

        list.set(1,"UI");
        System.out.println(list);
        list.add(2,"andir");
        System.out.println(list);
        for (Object o : list){
            System.out.println(o);
        }
        System.out.println("----------list 下标--------");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println("--------set--------");
        Set <String>set = new HashSet();
       // set.add(list);
        set.add("java");
        set.add("web");
        set.add("java");
        System.out.println(set);
        System.out.println(set.size());
        for (String s:set){
            System.out.print(s+" ");
        }

    }
}
